package com.lzw.breezeNovel.webApp.controller.user;

import com.lzw.breezeNovel.common.result.Result;
import com.lzw.breezeNovel.model.entity.pojo.user.LoginInfo;
import com.lzw.breezeNovel.model.entity.pojo.user.UserInfo;
import com.lzw.breezeNovel.model.entity.vo.CaptchaVo;
import com.lzw.breezeNovel.webApp.service.user.UserInfoService;
import com.lzw.breezeNovel.webApp.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 清风明月
 * @Package com.lzw.breezeNovel.webApp.controller
 * @date 2025/2/27
 * @description 用户信息控制类
 */

@RestController
@RequestMapping("/app")
@SuppressWarnings("all")
public class UserInfoController {

     @Autowired
     private UserInfoService userInfoService;


      @GetMapping("/login/getCode")
      @Operation(summary = "获取短信验证码")
      public Result getCode(@RequestParam String phone) {
         //调用服务层获取验证码
         userInfoService.getCode(phone);
        return Result.ok();
      }

    @Operation(summary = "获取图形验证码")
    @GetMapping("login/captcha")
    public Result<CaptchaVo> getCaptcha() {
        CaptchaVo captchaVo = userInfoService.getCaptcha();
        return Result.ok(captchaVo);
    }

      @PostMapping("/login")
      @Operation(summary = "用户登录")
      public Result<String> login(  @Validated() @RequestBody LoginInfo userInfo) {
          //调用服务层登录
          String token = userInfoService.login(userInfo);
          return Result.ok(token);
      }

      @PostMapping("/login/register")
      @Operation(summary = "用户注册")
      public Result<String> register(@Validated @RequestBody LoginInfo userInfo) {
            //调用服务层注册
            String token = userInfoService.register(userInfo);
            return Result.ok(token);
      }

      @GetMapping("/login/fogetPassword")
      @Operation(summary = "找回密码")
      public Result forgetPassword(@Validated @RequestBody LoginInfo userInfo) {
          //调用服务层找回密码
          userInfoService.forgetPassword(userInfo);
          return Result.ok();
      }

      @GetMapping("/getUserInfo")
      @Operation(summary = "获取用户信息")
      public Result<UserInfoVo> getUserInfo() {
             //调用服务层获取用户信息
             UserInfoVo userInfoVo = userInfoService.getUserInfo();
             return Result.ok(userInfoVo);
      }


      @PostMapping("/updateUserInfo")
      @Operation(summary = "修改用户信息")
      public Result updateUserInfo(@Validated @RequestBody UserInfo userInfo) {
          //调用服务层修改用户信息
          userInfoService.updateUserInfo(userInfo);
          return Result.ok();
      }


      @GetMapping("/updatePassword")
      @Operation(summary = "修改密码")
      public Result updatePassword(@Validated @RequestParam String oldPassword,@Validated @RequestParam String newPassword) {
          //调用服务层修改密码
          userInfoService.updatePassword(oldPassword,newPassword);
          return Result.ok();
      }




}
